<?php

defined('_AppMiage') or die('Restricted access');
if (isset($_GET['id']) && !empty($_GET['id']))
{
    $enseignant = new Enseignant($_GET['id']);
    $lstCriteres = $enseignant->getListCritere();
    ksort($lstCriteres);

    echo "{";
    echo '"error":"0",';
    echo '"id":"' . $enseignant->getIdUtilisateur() . '",';
    echo '"nom" :"' . $enseignant->getNomUtilisateur() . '",';
    echo '"prenom" :"' . $enseignant->getPrenomUtilisateur() . '",';
    echo '"message" :"' . $enseignant->getMessage() . '",';
    echo '"criteres" : [';
    $nbCriteresDiff = count($lstCriteres);
    $i = 1;
    foreach ($lstCriteres as $idType => $criteres)
    {
        echo '{';
        echo '"' . $idType . '" :[';
        $nbCriteres = count($criteres);
        $j = 1;
        foreach ($criteres as $id => $infos)
        {
            echo '{';
            echo '"idType":"' . $idType . '",';
            echo '"id":"' . $id . '",';
            switch ($idType)
            {
                case "1":
                    $promo = new Promo($id);
                    echo '"nom" :"' . $promo->getNom() . '",';
                    echo '"nbEtudiantMax" :"' . $infos['NbEtudiantMax'] . '",';
                    echo '"nbEtudiant" :"' . $infos['NbEtudiant'] . '"';
                    break;
                case "2":
                    global $zones;
                    echo '"nom" :"' . $zones[$id]['nom'] . '"';
                    break;
                case "3":
                    $tech = new Technologie($id);
                    echo '"nom" :"' . $tech->getNomTechnologie() . '"';
                    break;
                case "4":
                    $cat = new Categorie($id);
                    echo '"nom" :"' . $cat->getNomCategorie() . '"';
                    break;
                case "5":
                    $dom = new DomaineApplication($id);
                    echo '"nom" :"' . $dom->getNomDomaineApplication() . '"';
                    break;
            }
            if ($j == $nbCriteres)
            {
                echo '}';
            }
            else
            {
                echo '},';
            }
            $j = $j + 1;
        }
        echo ']';
        if ($i == $nbCriteresDiff)
        {
            echo '}';
        }
        else
        {
            echo '},';
        }
        $i = $i + 1;
    }
    echo ']';
    echo "}";
}
else
{
    echo "{error:1,msg:Veuillez s&eacute;lectionner un enseignant.}";
}
?>